# -*- coding: UTF-8 -*-
# def gen():
#         for c in 'AB':
#             yield c
#         for i in range(1,3):
#             yield i
#
# print (list(gen()))
#
# def gen():
#     yield from 'AB'
#     yield from range(1,3)
#
# print (list(gen()))



# from collections import Iterable
#
# def flatten(items, ignore_types=(str, bytes)):
#     for x in items:
#         if isinstance(x, Iterable) and not isinstance(x, ignore_types):
#             yield from flatten(x) # 这里递归调用，如果x是可迭代对象，继续分解
#         else:
#             yield x
#
#
# items = [1, 2, [3, 4, [5, 6], 7], 8]
#
# # Produces 1 2 3 4 5 6 7 8
# for x in flatten(items):
#     print(x)
#
# items = ['Dave', 'Paula', ['Thomas', 'Lewis']]
# for x in flatten(items):
#     print(x)
import inspect

def simple_coroutine():
    print('-> coroutine started')
    x = yield
    print(' -> coroutine received:', x)


my_coro = simple_coroutine()
print(my_coro)
print(inspect.getgeneratorstate(my_coro))

a = next(my_coro)
print(inspect.getgeneratorstate(my_coro))
print (a)
my_coro.send(42)
